<?php // content="text/plain; charset=utf-8"
require_once ('../include/jpgraph/jpgraph.php');
require_once ('../include/jpgraph/jpgraph_line.php');

require_once("../common.inc.php");
require_once(_INC_PATH.'database.php');

$db = new database();
$sql = "select count(id) as count,date_format(create_time,'%Y-%m')as per_month from tbl_estimate where date_format(create_time,'%Y-%m')<=date_format(curdate(),'%Y-%m') and date_format(create_time,'%Y-%m')>=date_format(curdate() - interval 6 month,'%Y-%m') group by per_month";
$db->setQuery($sql);
$data = $db->loadResultList("per_month","count");

$ydata = array();
$date_array = array();
$today = date("Y-m-d");
for($i = 5; $i >=0; $i--){
	array_push($date_array, date("Y-m",strtotime("$today -$i month")));
}
if($data)
{
	foreach($date_array as $value){
		if(array_key_exists($value,$data)){
			$ydata[] = $data[$value];
		}else{
			$ydata[] = 0;
		}
	}
}
// Some (random) data
//$ydata = array(11000,3252,8525,126965,51542,18595,96962,1322,5568,7000);

// Size of the overall graph
$width=800;
$height=300;

// Create the graph and set a scale.
// These two calls are always required
$graph = new Graph($width,$height);
$graph->SetScale('intlin');
$graph->SetShadow();

// Setup margin and titles
$graph->SetMargin(80,40,20,60);
$graph->title->Set('total number in the last 6 months');
$graph->SetMarginColor('#ffff88');
//$graph->subtitle->Set('(March 12, 2008)');
//$graph->xaxis->title->Set('Operator');
//$graph->yaxis->title->Set('');

$graph->yaxis->title->SetFont( FF_FONT1 , FS_BOLD );
$graph->xaxis->title->SetFont( FF_FONT1 , FS_BOLD );
$graph->xaxis->SetTickLabels($date_array);
$graph->xaxis->SetTextLabelInterval(1);


//$graph->yaxis->SetColor('blue');

// Create the linear plot
$lineplot=new LinePlot($ydata);
$lineplot->SetColor( 'blue' );
$lineplot->SetWeight( 2 );   // Two pixel wide
$lineplot->value->SetFont(FF_ARIAL,FS_BOLD);
$lineplot->value->SetColor('red');
$lineplot->value->SetFormatCallback('separator1000');
$lineplot->mark->SetType(MARK_UTRIANGLE);
$lineplot->mark->SetColor('blue');
$lineplot->mark->SetFillColor('red');

function separator1000($aVal) {
    return number_format($aVal);
}

$lineplot->value->Show();

// Add the plot to the graph
$graph->Add($lineplot);

// Display the graph
$graph->Stroke();
?>
